<%@page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@include file="/jsp/comm_css_include.jsp"%>
<!doctype html>
<html>
<head>
<style type="text/css">
.gray-bg {
	background-color: #fff;
}
</style>
</head>
<body class="gray-bg">
	<div class="ibox-content">
		<form class="form-horizontal m-t" id="commentForm">
			<table cellpadding="0" cellspacing="0" border="0"
				bordercolor="#3B95C8" width="100%" class="tablefont">
				<tr>
					<td width="25%" align="right"><label
						class="col-sm-3 control-label np">父字典名称：</label></td>
					<td width="75%">
						<div class="form-group">
							<div class="col-sm-8">
								<input id="parentId" name="parentId" type="hidden"> <input
									id="orgCode" name="orgCode" type="hidden"> <input
									id="parentCode" name="parentCode" type="hidden"> <input
									id="parentValue" name="parentValue" type="text"
									class="form-control" readonly="readonly" aria-required="true">
							</div>
						</div>
					</td>
				</tr>

				<tr>
					<td width="25%" align="right"><label
						class="col-sm-3 control-label np">所在省：</label></td>
					<td width="75%">
						<div class="form-group">
							<div class="col-sm-8">
								<select id="province" name="provinceId" class="select-control"></select>
							</div>
						</div>
					</td>
				</tr>

				<tr>
					<td width="25%" align="right"><label
						class="col-sm-3 control-label np">所在市：</label></td>
					<td width="75%">
						<div class="form-group">
							<div class="col-sm-8">
								<select id="city" name="cityId" class="select-control"></select>
							</div>
						</div>
					</td>
				</tr>

				<tr>
					<td width="25%" align="right"><label
						class="col-sm-3 control-label np">子字典名称：</label></td>
					<td width="75%">
						<div class="form-group">
							<div class="col-sm-8">
								<input id="orgName" name="orgName" type="text"
									class="form-control" required="required" aria-required="true"
									minlength="2" maxlength="20" placeholder="请输入名称(必填)" />
							</div>
						</div>
					</td>
				</tr>


				<tr>
					<td width="25%" align="right"><label
						class="col-sm-3 control-label np">单位级别：</label></td>
					<td width="75%">
						<div class="form-group">
							<div class="col-sm-8">
								<select class="select-control" id="orgLevel" name="orgLevel"></select>
							</div>
						</div>
					</td>
				</tr>

				<tr>
					<td width="25%" align="right"><label
						class="col-sm-3 control-label np">排序：</label></td>
					<td width="75%">
						<div class="form-group">
							<div class="col-sm-8">
								<input id="sortValue" name="sortValue" type="number" min="1"
									class="form-control" aria-required="true" minlength="1"
									maxlength="10" placeholder="请输入排序序号">
							</div>
						</div>
					</td>
				</tr>

				<tr>
					<td width="25%" align="right"><label
						class="col-sm-3 control-label np">备注：</label></td>
					<td width="75%">
						<div class="form-group">
							<div class="col-sm-8">
								<textarea id="remarks" name="remarks" cols="20" rows="5"
									type="text" class="form-control" aria-required="true"
									placeholder="请输入备注"></textarea>
							</div>
						</div>
					</td>
				</tr>

			</table>
			<table cellpadding="0" cellspacing="0" border="0"
				bordercolor="#3B95C8" width="100%">
				<tr>
					<td width="100%" align="center">
						<div class="ibox-content">
							<button type="button" class="btn dpbtn_green" onclick="save();">确定</button>
							<button type="button" class="btn dpbtn_red" onclick="Reset();">重置</button>
						</div>
					</td>
				</tr>
			</table>
		</form>
	</div>


	<!-- public quote -->
	<%@include file="/jsp/comm_js_include.jsp"%>
	<!-- custom js -->
	<%@include
		file="/js/common-dpqc/dpqc-validate/comm_validate_include.jsp"%>
	<!-- 区域选择 -->
	<%@include file="/jsp/comm_js_region_include_xz.jsp"%>
	<!--
    作者：zhangpp
    时间：2017-04-06
    描述：js
-->
	<script type="text/javascript">
	$(function(){
		$('#parentId').val($.getUrlData('parentId') || '');//父字典ID
		$('#orgCode').val($.getUrlData('orgCode') || '');//父字典orgCode
		$('#parentCode').val($.getUrlData('orgCode') || '');//父字典parentCode
		//父字典值
		var parentName = $.getUrlData("parentName");
    	var arr = parentName.split('<');
    	$("#parentValue").val(arr[0]);
    	
    	selectProvinces("0",function(){
    		selectCities("0");
    	});
    	
    	
	});
	
	$(function(){
		$.dpAjax({
	    	url:'${basePath}/DataDictionaryController/getEnableList',
 			data:{"parentValue":"BusiUnitLevel"},
 			success: function(datas){
					  var result = datas.result.rows;
					  var programme_sel=[];
				      for(var i=0;i<result.length;i++){
				          var programme = result[i];
				          programme_sel.push('<option value="'+programme.value+'">'+programme.name+'</option>')
				      }
				     $("#orgLevel").html(programme_sel.join(' '));
              }
	    	});
	 });
	
    var save = function () {
        var province = $('#province').val();
		if(province==0){
			layer.tips('这是必填字段', '#province');
			$("#province").focus();
			return;
		}
		
		var city = $('#city').val();
		if(city==0){
			layer.tips('这是必填字段', '#city');
			$("#city").focus();
			return;
		}
		
		var validstatus = $("#commentForm").valid();
        if (validstatus) {
            var data = $('#commentForm').serialize();
            $.dpAjax({
                url: '${basePath}/BaseBusiUnitController/save',
                data: data,
                success: function (datas) {
                    if (datas.flag == "100100") {
                        layer.msg("添加执行成功！", {icon: 6});
                        parent.layer.close(parent.addlayer);
                        return;
                    }
                    if (datas.flag == "100200") {
                        $.fn.showDatas({"datas": datas});
                        return;
                    }
                    layer.msg(datas.message, {icon: 2});
                }
            });
        }
    }

    var Reset = function(){
    	document.getElementById("province").value ="0";
    	document.getElementById("city").value ="0";
		document.getElementById("orgName").value ="";
		document.getElementById("sortValue").value ="";
		document.getElementById("remarks").value ="";
		document.getElementById("orgLevel").value ="01";
	}
    
    $(function(){	
        $("#commentForm").validate({
            //重写showErrors
            showErrors: function (errorMap, errorList) {
                
                $.each(errorList, function (i, v) {
                    layer.tips(v.message, v.element, { time: 1500 });
                    return false;
                });  
            },
            /* 失去焦点时验证 */
            onfocusout: function(element) { $(element).valid(); },
            /*  键盘抬起不验证 */
            onkeyup:false,
        });
    });  
</script>
</body>
</html>
